import pymysql

user= input('username:')
pswd= input('password:')
con= pymysql.connect(host= 'localhost',user= 'root',password= '',database='db3')
cursor= con.cursor(cursor=pymysql.cursors.DictCursor)#  查询的时候是字典查询
#  sql="select * from userinfo where username='%s' and password='%s'" %(user,pswd)
#  不要自己进行字符串拼接，很容易被写入注释
sql='select * from userinfo where username=%s and password=%s'
cursor.execute(sql,[user,pswd])   #  后面参数支持列表和字典
ret=cursor.fetchone()
print(ret)
if ret:
    print('登录成功')
else:
    print('登陆失败')
